#include <iostream>
using namespace std;

class Automobile
{
private:
    int power;
public:
    Automobile(int power);
    ~Automobile();
    void show();
};

Automobile::Automobile(int power)
{   
    cout << "construct Automobile ..." << endl;
    this->power = power;
}

void Automobile::show() {
    cout << " power : " << power << endl;
}


Automobile::~Automobile()
{
    cout << "destruct Automobile ..." << endl;
}




class Car : virtual public Automobile
{
private:
    int power;
    int seat;
public:
    Car(int power, int seat);
    ~Car();
    void show();
};

Car::Car(int power, int seat) : Automobile(power)
{   
    cout << "construct Car ..." << endl;
    // this->power = power;
    this->seat = seat;
}


void Car::show(){
    cout << "car power: ";
    Automobile::show();
    cout<<" seat: " << this->seat << endl;
}

Car::~Car()
{
    cout << "destruct Car ..." << endl;
}


class Wagon : virtual public Automobile
{
private:
    int power;
    int load;
public:
    Wagon(int power, int load);
    ~Wagon();
    void show();
};

Wagon::Wagon(int power, int load) : Automobile(power)
{   
    cout << "construct Wagon ..." << endl;
    // this->power = power;
    this->load = load;
}


void Wagon::show(){
    cout << "Wagon power: ";
    Automobile::show();
    cout<<" load: " << this->load << endl;
}

Wagon::~Wagon()
{
    cout << "destruct Wagon ..." << endl;
}

class StationWagon : public Car, public Wagon
{
private:
    /* data */
public:
    StationWagon(int Cpower, int Wpower, int seat, int load);
    ~StationWagon();
    void ShowSW();
};

StationWagon::StationWagon(int Cpower, int Wpower, int seat, int load):Automobile(Cpower), Wagon(Wpower, load), Car(Cpower, seat)
{
    cout << "construct StationWagon ..." << endl;
}

void StationWagon::ShowSW() {
    cout << "StationWagon : " << endl;
    Car::show();
    Wagon::show();
}

StationWagon::~StationWagon()
{
    cout << "destruct StationWagon ..." << endl;
}


int main() {
    StationWagon sw(105,108,3,8);
    // sw.show();
    sw.ShowSW();

    return 0;
}

/**
 * construct Automobile ...
construct Car ...
construct Automobile ...
construct Wagon ...
construct StationWagon ...
StationWagon :
car power:  power : 105
 seat: 3
Wagon power:  power : 108
 load: 8
destruct StationWagon ...
destruct Wagon ...
destruct Automobile ...
destruct Car ...
destruct Automobile ...
 * 
加了 virtual虚基类之后，Automobile只构造一次
construct Automobile ...
construct Car ...
construct Wagon ...
construct StationWagon ...
StationWagon :
car power:  power : 105
 seat: 3
Wagon power:  power : 105
 load: 8
destruct StationWagon ...
destruct Wagon ...
destruct Car ...
destruct Automobile ...
*/

